﻿<!DOCTYPE html>
<!--培训课件管理编辑-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>
    <link href="../static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="../static/js/vue-treeselect/vue-treeselect.js"></script>
    <style>
        .vue-treeselect__control {
            height: 100%;
            border: none;
            background: none;
        }

        .vue-treeselect__placeholder {
            top: -3px;
        }

        .vue-treeselect__single-value {
            top: -3px;
        }

        .el-input__suffix {
            /* z-index: 9; */
        }

        .el-form-item__content {
            line-height: 28px !important;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak class="popupW100">
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px"
                 size="mini">
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.trainingCoursewareName" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{TrainingCourseware.TrainingCoursewareName+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{TrainingCourseware.TrainingCoursewareTypeName+mark.m}}</div>
                                </template>
                                <!--<el-select @visible-change="visibleChange" v-model="Form.courseClassId" slot="suffix"
               :placeholder="TrainingCourseware.TrainingCoursewareTypeName">
        <el-option label="请选择" value=""></el-option>
        <el-option v-for="item in TrainingCoursewareTypeName" :label="item.name"
                   :value="item.id">
        </el-option>
    </el-select>-->
                                <treeselect v-model="Form.courseClassId"
                                            :options="TrainingCoursewareTypeName"
                                            :flat="true"
                                            slot="suffix"
                                            :disable-branch-nodes="true"
                                            style="line-height: 28px;width:70%;float: right;"
                                            placeholder="请选择" />
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <div class="el-input--mini el-input-group">
                                <div class="el-input-group__prepend">
                                    {{TrainingCourseware.TrainingCoursewareContentSummary+mark.m}}
                                </div>
                                <el-input class="el-textarea__inner" type="textarea"
                                          v-model="Form.trainingCoursewareContent" autocomplete="off"></el-input>
                            </div>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.attachmentName" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{"附件"+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                    
                </el-col>
                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">

                        <el-form-item>

                            <el-upload name="files" class="fl" ref="Attachmentupload" action="/api/File/UploadFile"
                                       :before-upload="beforeUpload" :on-success="successUpLoad" :auto-upload="true"
                                       :show-file-list="false">
                                <el-button type="primary">{{col.lawUploadAttachment}}</el-button>
                            </el-upload>
                        </el-form-item>
                    </div>
                </el-col>
</el-row>
            <el-row type="flex" justify="end">
                <el-form-item>
                    <!--<el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSave}}</el-button>-->
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnCommit}}</el-button>
                    <el-button type="primary" @click="onBack">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>
    </div>
    <script type="text/javascript">
        var uploadText = "请选择上传文件";
        var app = new Vue({
            el: '#app',
            data: {
                id: '',
                UploadFileApiUrl: API_UPLOADFILE_URL,
                //业务表单内容
                Form: {
                    id: guidEmpty,
                    trainingCoursewareName: '',
                    trainingCoursewareContent: '',
                    trainingCoursewareTypeName: '',
                    //courseClassId: '',
                    attachmentId: '',
                    attachmentName:'',

                },
                TrainingCoursewareTypeName: [],
                Sex: [],
                //表单验证
                rules: {
                    TrainingCoursewareName: [
                        verification.NotNull,
                        { pattern: verification.StringLengthAtoB.t.format(2, 50), message: verification.StringLengthAtoB.m.format(2, 5), trigger: 'blur' }
                    ],

                    //courseClassId: [
                    //    verification.NotNull
                    //]
                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },

                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            if (mythis.Form.trainingCoursewareName == null || mythis.Form.trainingCoursewareName == "" || mythis.Form.trainingCoursewareName == undefined) {
                                alert('请输入培训课件名称');
                                return;
                            }
                            if (mythis.Form.courseClassId == null || mythis.Form.courseClassId == "" || mythis.Form.courseClassId == undefined) {
                                alert('请选择课件类型');
                                return;
                            }
                            if (mythis.Form.trainingCoursewareContent == null || mythis.Form.trainingCoursewareContent == "" || mythis.Form.trainingCoursewareContent == undefined) {
                                alert('请输入培训课件内容概要');
                                return;
                            }
                            onSubmitForm(this, '/api/CBS_Course/Save', mythis.Form);
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                getData: function () {
                    getData(this, '/api/CBS_Course/get?id=' + this.id);
                },
                onBack: function () {
                    parent.app.ListItem.dialogVisible = false;
                },
                 //初始化课件类型
                getClassList: function () {
                    var mythis = this;
                    //myAjax("post", this, '/api/CBS_CourseClass/GetList', { model: { PId: null }, offset: 0, limit: 100 }, function (response) {
                    //    mythis.TrainingCoursewareTypeName = response.data.pageData;

                    //    //console.log(response.data.pageData);
                    //}, false);
                    //myAjax("post", this, '/api/CBS_CourseClass/GetList', { model: { PId: null }, offset: 0, limit: 100 }, function (response) {
                    //    mythis.TrainingCoursewareTypeName =MenuHelper(response.data.pageData, null);
                    //}, false);
                    myAjax("post", this, '/api/PX_CourseClass/GetList', { model: {}, offset: 0, limit: 100 }, function (response) {
                        var data = MenuHelper(response.data.pageData, guidEmpty);
                        mythis.TrainingCoursewareTypeName = data;
                    }, false);
                },
                //上传附件文件的校验
                beforeUpload: function (file) {
                    const isJPG = file.type === 'image/jpeg';
                    const isPNG = file.type === 'image/png';
                    const isLt2M = file.size / 1024 / 1024 < 2;
                    //if (!isJPG && !isPNG) {
                    //    this.$message.error('仅可上传 JPG和PNG 格式!');
                    //}
                    if (!isLt2M) {
                        this.$message.error('上传图片大小不能超过 2MB!');
                    }
                    return isLt2M; //(isJPG || isPNG) && 
                },
                //上传成功后执行
                successUpLoad: function (res, file) {
                    var data = res.data;//成功后的业务数据
                    var fileModel = data[0];//第一个文件对象
                    //var d = new Date();
                    this.Form.attachmentId = fileModel.id;
                    this.Form.attachmentName = file.name;
                    //this.Form.cbs_list.cbS_ListAttachments.push({
                    //    attachment: fileModel.id,
                    //    path: downLoadPath(fileModel.id),
                    //    name: file.name,
                    //    cbS_ListId: this.id,
                    //    uploadTime: new Date(d.setHours(d.getHours() + 8)).toJSON().substr(0, 19).replace('T', ' '),
                    //    uploadUser: this.Form.sysUser.id,
                    //    sysUser: {
                    //        sysUserInfor: { name: this.Form.sysUser.name, }
                    //    }
                    //});
                },
            },
            mounted: function () {
                //this.TrainingCoursewareTypeName = getDicData('27');
                this.getClassList();
                this.id = getUrlParam("id");
                this.getData();
            }
        });
        function MenuHelper(list, pid) {
            var result = [];
            list.forEach(function (v, i) {
                if (v.pId == pid) {
                    var obj = v;
                    obj.id = obj.id + '';
                    obj.label = obj.name + '';
                    var nextObj = MenuHelper(list, v.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
    </script>
</body>

</html>